class CreateFeeds < ActiveRecord::Migration
  def self.up
    add_column :users, :money, :integer, :default => 0
    add_column :users, :draw_money_duration_days, :integer, :default => 0
    add_column :users, :money_drawn_on, :date
    add_column :user_tool_settings, :consumed_on, :date
    add_column :tools, :month_fare,:integer, :default => 0    
    add_column :infos, :money,:integer, :default => 0
    add_column :infos, :money_purpose,:string, :default => 'none'
    create_table :feeds do |t|      
      t.integer :version
      t.string :type
      # money_history
      t.integer :user_id,
        :tool_id,
        :introducedor_id,
        :info_id
      t.integer :money,        
        :added_money,
        :subed_money,
        :default => 0
      t.string :mobile      
      t.timestamps
    end
    User.all.each do |user|
      Feed::MoneyJoin.create!(
        :user_id => user.id
      )
      Feed::MoneyLogo.create!(
        :user_id => user.id
      ) if user.user_logo.present?
      Feed::MoneyFetion.create!(
        :user_id => user.id
      ) if user.mobile?
    end if not Rails.env.test?
  end

  def self.down
    drop_table :feeds
    remove_columns :users, :money, :draw_money_duration_days, :money_drawn_on
    remove_column :user_tool_settings, :consumed_on
    remove_column :tools, :month_fare
    remove_columns :infos, :money, :money_purpose
  end
end
